Micron Document
Fox's Git Mirrors


Displaying Raw • Download

pkg/node/netmon.go 201d27032fbc0af2fd0a560de603cd8786ee75b5 (201d2703) Text, 951 B

// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2024-2026 Quad4.io

//go:build !js

package node

import (
"time"

"quad4/reticulum-go/pkg/debug"
"quad4/reticulum-go/pkg/health"
)

const interfaceMonitorInterval = 10 * time.Second

// startInterfaceMonitor polls OS network interfaces and calls OnNetworkAvailable
// when link state or addresses change. Uses net.Interfaces and works on Linux,
// Android, Windows, macOS, and BSD on any CPU architecture.
func (n *Node) startInterfaceMonitor() {
go func() {
ticker := time.NewTicker(interfaceMonitorInterval)
defer ticker.Stop()
last := currentInterfaceSnapshot()
for range ticker.C {
cur := currentInterfaceSnapshot()
if interfaceSnapshotsEqual(last, cur) {
continue
}
last = cur
health.Inc("", health.KindNetmonFlap)
if err := n.OnNetworkAvailable(); err != nil {
debug.Log(debug.DebugVerbose, "interface monitor refresh", "error", err)
}
}
}()
}

Served by rngit 1.5.2 - Generated in 0.02s